/**
 * creater:kunjiang.zhou@dhc.com.cn
 * create time:2017-05-31 15:53:45
 * describe:主页
 */
APP.controller('MainController', ['$scope', 'MainService','$state','$ionicPopup','UserService',
  function ($scope, MainService,$state,$ionicPopup,UserService) {

    /***变量声明***/
    $scope.username = undefined;
    $scope.password = undefined;

    /**
     * 初始化函数
     */
    $scope.init = function () {

    };

    /**
     * 退出登录方法
     */
    $scope.outLogin = function () {
        var confirmPopup = $ionicPopup.confirm({
            template: '确认退出登录?',
            cancelText: '取消',
            okText: '确定'
        });
        confirmPopup.then(function(res) {
            if(res) {
                UserService.clearUser();
                $state.go('login');
            } else {
                console.log('You are not sure');
            }
        });
    };
    //上线
    $scope.online = function () {
      $state.go('online');
    };
    //下线
    $scope.outline = function () {
      $state.go('outline');
    };
    //入库
    $scope.input = function () {
      $state.go('input');
    };
    //生成条码
    $scope.generate = function () {
      $state.go('generate');
    };
    //二次入库
    $scope.inputSecond = function () {
      $state.go('inputSecond');
    };


    /*
     $scope.init();//如果页面缓存则用此方法初始化
     */
    $scope.$on('$ionicView.beforeEnter', function () {
      $scope.init();
    });
  }
]);

/**
 * creater:kunjiang.zhou@dhc.com.cn
 * create time:2017-05-31 15:53:45
 * describe:主页
 */
APP.service('MainService', ['$http', 'UrlService', function ($http, UrlService) {
  /**
   * 登录方法
   * @param username  登录用户名
   * @param password  登录密码
   */
  this.doLogin = function (username, password) {
    var param = {
      username: username,
      password: password
    };
    return $http.post(UrlService.getUrl('LOGIN'), param);
  }

}]);
